#include "Camera.h"

namespace soft_renderer
{
	Camera::Camera()
	{
		position.set(100, 0, 0);
		up.set(0, 1, 0);
		target.set(0, 0, 0);

		updateViewMatrix();
	}

	void Camera::updateViewMatrix()
	{
		// http://eclipseflower.github.io/2017/01/11/View-Matrix/
		_viewMatrix.lookAt(position, target, up);
		// Matrix4 translateMatrix;
		// translateMatrix.setTranslation(position.negated());
		double dist = position.length();
		_viewMatrix.setTranslation(Vector3(0, 0, -dist));
	}

	void Camera::setPosition(Vector3 position)
	{
		this->position.copy(position);
	}

	void Camera::setTarget(Vector3 target)
	{
		this->target.copy(target);
	}

	void Camera::setUp(Vector3 up)
	{
		this->up.copy(up);
	}

	const Matrix4& Camera::viewMatrix() const
	{
		return _viewMatrix;
	}

	const Matrix4& Camera::projectionMatrix() const
	{
		return _projectionMatrix;
	}
}


